/*--------------------劳务模块.工种管理--ly-----------------*/
/*--------------------工种信息修改功能  lb_job_edit.html------------------*/

$(document).ready(function() {

	//获取cookie:ueserid & Wtid
	var jobid = $.cookie("jobid");
	var editcookie = $.cookie("nav");
	var Wtid = JSON.parse(editcookie).w;

	//填充数据
	var searchurl = laborport + '/LabourJobController/selectById'; //查询
	$.post(searchurl, {
		'jobId': jobid,
	}, function(result) {
		var code = result.code;
		var editlist = result.object;
		if(code == 0) {
			$("#L_jobname").val(editlist.jobname); //工种名称
			$("#L_description").val(editlist.description); //技能描述
			$("#L_daywage").val(editlist.daywage); //平均日薪
			$("#L_url").val(editlist.url); //工种LogoURL
			$("#L_make").val(editlist.make); //技能标签
		} else {
			console.log("网络不佳，稍后再试！")
		}
	});

	//layui
	layui.use(['form', 'layer'], function() {
		$ = layui.jquery;
		var form = layui.form,
			layer = layui.layer;

		//自定义验证规则
		form.verify({
			username: function(value) {
				if(value.length < 3) {
					return '昵称至少得5个字符啊';
				}
			},
		});

		//获取表单数据
		$("input").blur(function() {
			//失去焦点事件
			var jobname = $("#L_jobname").val(); //工种名称
			var description = $("#L_description").val(); //技能描述
			var daywage = $("#L_daywage").val(); //平均日薪
			var url = $("#L_url").val(); //工种LogoURL
			var make = $("#L_make").val(); //技能标签
			//监听提交
			form.on('submit(edit)', function() {
				//递交修改
				editData(jobname, description,daywage,url,make);
				return false;
			});
		});

		//修改用户信息
		var editurl = laborport + '/LabourJobController/update'; //修改
		// 获得frame索引
		var index = parent.layer.getFrameIndex(window.name);
		var editData = function(jobname,description,daywage,url,make) {
			console.log(jobname, description,daywage,url,make);
			//修改 edit
			$.post(editurl, {
				jobid: jobid,
				jobname: jobname,
				description: description,
				daywage: daywage,
				url: url, 
				make: make,
			}, function(result) {
				var code = result.code;
				if(code == 0) {
					layer.msg('修改成功!', {
						icon: 1,
						time: 1000
					}, function() {
						//关闭当前frame
						parent.layer.close(index);
					});
				} else {
					layer.msg('网络开小差了，请稍后再试!', {
						icon: 2,
						time: 1000
					}, function() {
						//关闭当前frame
//						parent.layer.close(index);
					});
				}
			})
		}

	});
})